package edu.gatech.oad.mule;

import java.awt.event.WindowEvent;
import java.awt.event.WindowFocusListener;
import java.awt.event.WindowListener;

import javax.swing.JFrame;

/**
 * This class represents the store GUI that pops up when the player
 * interacts with the store.
 *
 * @author Brendan McGarry, Dale Avery, D'Miria Collins, Natasha Parekh, Jaemin Park
 * @version %I%, %G%
 */
public class StoreGUI extends JFrame implements WindowListener, WindowFocusListener {
	
	private Wallet w;
	private Player p;
	private StorePanel sp;
	
	/**
	 * This constructor creates a new GUI for the store
	 * 
	 * @param p An instance of the player interacting with this store
	 * @param w An instance of the store's wallet
	 */
	public StoreGUI(Wallet w, Player p){
		//call to the JFrame constructor
		super("Town Store");
		//save the towns wallet and the player's wallet
		this.w = w;
		this.p = p;
		//create a new store panel with the GUI components
		sp = new StorePanel(w, p);
		add(sp);
		//add a focus listener to lock in the focus
		addWindowFocusListener(this);
		//add window listener to intercept closing events
		addWindowListener(this);
		//center, make invisible (for now), and center
		setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
		pack();
		setLocationRelativeTo(null);
		setVisible(false);
	}//end constructor

	/**
	 * Changes the player interacting with this GUI
	 * 
	 * @param p The player interacting with this GUI
	 */
	public void setPlayer(Player p){
		sp.setPlayer(p);
	}//end method setPlayer
	
	/**
	 * Show's the store's GUI
	 */
	public void showGUI(){
		sp.updateSelectors();
		setLocationRelativeTo(null);
		setVisible(true);
	}//end method showGUI
	
	//====================
	//	WindowFocusListener
	//====================
	
	@Override
	public void windowGainedFocus(WindowEvent e) {
		System.out.println("gained focus");		
	}//end method windowGainedFocus

	@Override
	public void windowLostFocus(WindowEvent e) {
		System.out.println("lost focus");	
		requestFocus();
	}//end method windowLostFocus	

	//====================
	//	WindowListener
	//====================
	
	@Override
	public void windowOpened(WindowEvent e) {
		// TODO Auto-generated method stub		
	}//end method windowOpened

	@Override
	public void windowClosing(WindowEvent e) {
		System.out.println("closing window");
		setVisible(false);
	}//end method windowClosing

	@Override
	public void windowClosed(WindowEvent e) {
		// TODO Auto-generated method stub		
	}//end method windowClosed

	@Override
	public void windowIconified(WindowEvent e) {
		// TODO Auto-generated method stub		
	}//end method windowIconified

	@Override
	public void windowDeiconified(WindowEvent e) {
		// TODO Auto-generated method stub		
	}//end method windowDeiconified

	@Override
	public void windowActivated(WindowEvent e) {
		// TODO Auto-generated method stub		
	}//end method windowActivated

	@Override
	public void windowDeactivated(WindowEvent e) {
		// TODO Auto-generated method stub		
	}//end method windowDeactivated
	
}//end class StoreGUI
